package sphinx

import (
	"fmt"
	"github.com/go-martini/martini"
	"net/http"
	"server/lib/Imartini"
	"server/lib/sphinx"
)

func index(param martini.Params, res http.ResponseWriter, req *http.Request, log *Imartini.Mlog) {
	// // 获取实例信息
	// status, err := spClient.Status()
	// if err != nil {
	//  log.Fatal("err3:", err)
	// }

	// for _, row := range status {
	//  log.Printf("%20s:\t%s\n", row[0], row[1])
	// }

	// 查询
	// a := sphinx.GetClient()
	// a.Text()
	search := sphinx.GetClient()
	defer search.Close()
	// search.AddQuery(param["q"], "test1", "")
	ret, err := search.Query(param["q"], "*", "") //.RunQueries() //
	// log.Println(res.Total)
	if err != nil {
		res.Write([]byte(fmt.Sprintf("%v", err)))
	}

	res.Write([]byte(fmt.Sprintf("%v\n", ret)))

	//使用mysql查询sphinx
	searchql := sphinx.GetSearchql()
	ret2, _ := searchql.IExecute("select * from rt")

	res.Write([]byte(fmt.Sprintf("%v\n", ret2)))
}
